<?php
/* 标签控制器
* @Author: {daifei}
* @Date:   2014-03-20 18:53:37
* @Last Modified by:   {daifei}
* @Last Modified time: 2014-03-21 18:10:58
*/

	class TagControl extends CommonControl{
		private $model;
		public function __init(){
			parent::__init();
			$this->model=K('tag');
		}
		/**
		 * [index 标签主页]
		 * @return [type] [description]
		 */
		public function index (){
			
			// p($data);die;
			if(IS_AJAX){
				//执行修改数据
					$this->model->update_data();
					$return =array(
						'state'	=>1,
						'message'	=>'修改成功',
						'timeout'	=>2
						);
					$this->ajax($return);
				
			}
			//结果来的数组有份额与所以需要进行分割
			$data=$this->model->get_data();
			$page=$data['page'];
			unset($data['page']);
			//将分页 卸载掉的数组 传到页面中去
			$this->assign('data' ,$data);
			$this->assign('page' ,$page);
			
			$this->display();
		}
		/**
		 * [add_tag 添加标签]
		 */
		public function add_tag(){
			//先判断验证是否成功
			if(IS_AJAX){
				if(!$this->model->create()){
					$return =array(
						'state'	=>0,
						'message'	=>$this->model->error,
						'timeout'	=>2
						);
					$this->ajax($return);
				}
				if($this->model->add_data()){
					$return =array(
						'state'		=>1,
						'message'	=>'操作成功',
						'timeout'	=>2
						);

				}else{
					$return =array(
						'state'		=>0,
						'message'	=>$this->model->error,
						'timeout'	=>2
						);
				}
				$this->ajax($return);

			}
			$this->display();

		}
		/**
		 * [del_tag d删除标签]
		 * @return [type] [description]
		 */
		public function del_tag(){
			if(IS_AJAX){
				$tid=Q('tid' , 0, 'intval');
				$this->model->del_data($tid);
				$return=array(
					'state'	=>1,
					'message'	=>'删除成功',
					'timeout'	=>2
					);
				$this->ajax($return);
			}
		}
		

	}
?>
